package personresources.manager.util;

import javax.faces.application.Application;
import javax.faces.application.NavigationHandler;
import javax.faces.context.FacesContext;

/**
 * Common util for project
 * @author Duy Chuong
 * @version 
 */

public class CommonUtils {
	private static final String SCREEN_ERROR_ID = "errorPage";
	/**
	 * Forward to Screen with id in faces-navigator.xml 
	 * 
	 * @author Duy Chuong
	 * @param context FacesContext
	 * @param viewId id of screen in faces-navigator. If viewId = null then forward to error page
	 */
	public static void doBackError(FacesContext context, String viewId) {
		if (viewId == null) {
			viewId = SCREEN_ERROR_ID;
		}
		
		Application application = context.getApplication();
		NavigationHandler navigator = application.getNavigationHandler();
		navigator.handleNavigation(context, null, viewId);
		context.renderResponse();
	}

}
